<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/9/3
  Time: 17:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>列表</title>
    <script src="statics/layui.js"></script>
    <link rel="stylesheet" href="statics/css/layui.css"/>
    <script src="statics/jquery-1.6.2.min.js"></script>
</head>
<style>
    tr,th {
        text-align: center;
    }

    #div {
        width: 1200px;
        margin: 0px auto;
    }

    h1 {
        margin-left: 400px;
    }

    #page {
        margin-left: 370px;
    }
</style>
<body>
<div id="div">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>电影信息列表</legend>
    </fieldset>
    <form method="post" action="toAdd">
        <input type="submit" value="添加电影"  class="layui-btn layui-btn-normal">
    </form>
    <table border="1" class="layui-table">
        <thead>
        <tr>
            <th>电影编号:</th>
            <th>电影名称:</th>
            <th>电影类型:</th>
            <th>电影价格:</th>
            <th>是否推荐:</th>
            <th>上映时间:</th>
            <th>下映时间:</th>
            <th>投票数:</th>
            <th>编辑:</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="l">
            <tr>
                <td>${l.movieId}</td>
                <td>${l.movieName}</td>
                <td>${l.movieType}</td>
                <td>${l.price}</td>
                <td>
                    <c:if test="${l.recommend==0}">
                        不推荐
                    </c:if>
                    <c:if test="${l.recommend==1}">
                        推荐
                    </c:if>
                </td>
                <td><fmt:formatDate value="${l.startTime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
                <td><fmt:formatDate value="${l.endTime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
                <td>${l.votes}</td>
                <td>
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="javascript:location.href='view/${l.movieId}'"><i class="layui-icon layui-icon-heart"></i></button>
                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="javascript:location.href='upd?movieId=${l.movieId}'"><i class="layui-icon"></i></button>
                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="javascript:del(${l.movieId})"><i class="layui-icon"></i></button>
                    </div>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div id="page">
        <c:if test="${pageIndex!=1}">
            <a href="list?pageIndex=1">首页</a>
        </c:if>
        <c:if test="${pageIndex>1}">
            <a href="list?pageIndex=${pageIndex-1}">上一页</a>
        </c:if>
        <c:if test="${pageIndex<pageNum}">
            <a href="list?pageIndex=${pageIndex+1}">下一页</a>
        </c:if>
        <c:if test="${pageIndex!=pageNum}">
            <a href="list?pageIndex=${pageNum}">尾页</a>
        </c:if>
        第${pageIndex}页,共${pageNum}页，总记录数${count}条
    </div>
</div>
</body>
<script>
    function del(movieId) {
        $.ajax({
            url:"del/"+movieId,
            type:"delete",
            success:function (data) {
                if (data=="true"){
                    alert("删除成功！")
                }else {
                    alert("删除失败！")
                }
                location.reload();
            }
        })
    }
</script>
</html>
